/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 * 假设只有唯一解
 */
var twoSum = function(nums, target) {
    let i, map = new Map(), length = nums.length;
    for(i = 0; i < length; i++){
        if(map.has(nums[i])){
            return [map.get(nums[i]), i];
        } else {
            map.set(target - nums[i],i);
        }
    }
    return [-1, -1];
};

console.log(twoSum([3,2,4],6));